//tohtml.js

var app = getApp()
Page({
	data: {
		pagedata: {},
		bool:false,
		pagetitle:app.setting.title,
		url:'',
		nodatapic_close:true,
	},
	onReady: function () {
	},
	onPullDownRefresh: function (){
		var the=this;
		var opt={};
		the.onLoad(opt);
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (option) {
		var the=this;
		if(option.isgoshare){
				the.setData({
					ShowGoshare:true,
				});
			}
		wx.setNavigationBarTitle({'title':the.data.pagetitle});
		if(option.url){
			option.url=decodeURIComponent(option.url);
			app.util.access(option.url);
		}else{
			var h5url='';
			if(option.h5url){
				h5url=decodeURIComponent(option.h5url);
			}
			app.util.session(function(ssid){
				the.start(ssid,h5url);
			});
		}
	},
	start:function(ssid,h5url){
		if(h5url){
			var url=h5url;
		}else{
      	wx.navigateTo({'url':'/'+app.plugin_name+'/index/index'});
		}
		//判断来自管理端
		if(url.indexOf('custom') == -1){
			app.setting.index_url_new=app.setting.siteroot+'manage/index.php?wxgid='+app.setting.wxgid
			app.setting.api_url_new=app.setting.siteroot+'api.php?this=manage'
			app.setting.manage=1;
		}else{
			app.setting.manage=0;
		}
		if(url.slice(-4)=='.php'){
			url +='?';
		}else if(url.indexOf('?') == -1 && app.setting.manage==1){
			url +='/manage/index.php?';
		}else if(url.indexOf('?') == -1 && app.setting.manage!=1){
			url +='/custom/index.php?';
		}else{
			url +='&';
		}
		var app_openid=app.openid?app.openid:'';		
		url +='i='+app.setting.uniacid+'&fromh5wxapp=1&wxapp_id='+app.setting.wxgid+'&app_openid='+app_openid;
		console.log('url');console.log(url);
		this.setData({
			url:url,
			bool:true,
		});
	},
	onShareAppMessage: function (res) {
		if (res.from === 'button') {
		  // 来自页面内转发按钮
		  console.log(res.target)
		}
		var path='/pages/index/index';
		if(res.webViewUrl){
			var h5url=app.util.h5url(res.webViewUrl);
			console.log(h5url)
			path +='?h5url='+encodeURIComponent(h5url);
		}
		return {
		  title: app.setting.title,
		  desc: app.setting.desc,
		  path: path,
		  success: function(res) {
			// 转发成功
		  },
		  fail: function(res) {
			// 转发失败
		  }
		}
	},
	onShareTimeline: function (res) {
		var the = this
		var pagedata = the.data.pagedata
		var query=''
		if(app.access.op){
			query +='&op='+app.access.op;
		}
		if(pagedata.fromuser){
			query +='&fromuser='+pagedata.fromuser;
		}
		query +='&isgoshare=1'
		return {
		  title: the.data.pagetitle,
		  query: query,
		  desc: app.setting.sharedesc,
		  success: function(res) {
		  },
		  fail: function(res) {
		  }
		}
	},
});